<!DOCTYPE html>
<!--王艳辉-->
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>班级授课老师</title>
    <link rel="stylesheet" type="text/css" href="plugin/layui/css/layui.css"/>
    <script src="plugin/layui/layui.js" type="text/javascript" charset="utf-8"></script>
</head>
<body>


<table id="instructor" lay-filter="instructor"></table>

<!-- 更新类型弹出层 -->
<div id="update-instructor-layer" style="display: none; padding: 20px;margin-left: 100px">
    <form id="update-instructor-form" class="layui-form layui-form-pane" lay-filter="update-class-form">
        <div class="layui-form-item" style="display: none">
            <label class="layui-form-label">teId</label>
            <div class="layui-input-inline">
                <input type="text" name="teId" id="teId" class="layui-input" lay-verify="required">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">班级</label>
            <div class="layui-input-inline">
                <input type="text" name="teamname" id="teamname" required lay-verify="required"  autocomplete="off" class="layui-input" readonly>
            </div>
            <label class="layui-form-label">生物</label>
            <div class="layui-input-inline">
                <select id="biology" name="biology" lay-verify="required" lay-search="">
                    <option value="">未选择</option>
                </select>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">语文</label>
            <div class="layui-input-inline">
                <select id="chinese" name="chinese" lay-verify="required" lay-search="">
                    <option value="">未选择</option>
                </select>
            </div>
            <label class="layui-form-label">数学</label>
            <div class="layui-input-inline">
                <select id="math" name="math" lay-verify="required" lay-search="">
                    <option value="">未选择</option>
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">英语</label>
            <div class="layui-input-inline">
                <select id="english" name="english" lay-verify="required" lay-search="">
                    <option value="">未选择</option>
                </select>
            </div>
            <label class="layui-form-label">物理</label>
            <div class="layui-input-inline">
                <select id="physics" name="physics" lay-verify="required" lay-search="">
                    <option value="">未选择</option>
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">化学</label>
            <div class="layui-input-inline">
                <select id="chemistry" name="chemistry" lay-verify="required" lay-search="">
                    <option value="">未选择</option>
                </select>
            </div>
            <label class="layui-form-label">生物</label>
            <div class="layui-input-inline">
                <select id="geography" name="geography" lay-verify="required" lay-search="">
                    <option value="">未选择</option>
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">历史</label>
            <div class="layui-input-inline">
                <select id="history" name="history" lay-verify="required" lay-search="">
                    <option value="">未选择</option>
                </select>
            </div>
            <label class="layui-form-label">政治</label>
            <div class="layui-input-inline">
                <select id="polotics" name="polotics" lay-verify="required" lay-search="">
                    <option value="" checked="checked">未选择</option>
                </select>
            </div>
        </div>

    </form>
</div>
<script>
    layui.use(['table', 'jquery', 'layer', 'form', 'laydate'], function () {
        // 加载layui模块，使用其推荐的【预先加载】方式，详见官网【模块规范】一节
        var table = layui.table;
        var $ = layui.$;
        var layer = layui.layer;
        var form = layui.form;
        var laydate = layui.laydate;

        //监听行双击修改事件
        table.on('rowDouble(instructor)', function(obj){
            var data = obj.data; //获得当前行数据
            //给修改框设置值
            $("#teId").val(data.teId);
            $("#teamname").val(data.teamInfo.gradeInfo.gradeType + "(" + data.teamInfo.tname+")");

            //清空所有老师下拉框
            $("#chinese").empty();
            $("#math").empty();
            $("#english").empty();
            $("#physics").empty();
            $("#chemistry").empty();
            $("#geography").empty();
            $("#history").empty();
            $("#polotics").empty();
            $("#biology").empty();

            //获取当前学校所有老师信息
            $.ajax({
                url: '/teacher/getall',   //后台数据地址
                success: function (datares) {
                    var res=datares.data
                    //整体未选择项
                    $("#chinese").prepend("<option value=0>" +"未选择"+ "</option>");
                    $("#math").prepend("<option value=0>" +"未选择"+ "</option>");
                    $("#english").prepend("<option value=0>" +"未选择"+ "</option>");
                    $("#physics").prepend("<option value=0>" +"未选择"+ "</option>");
                    $("#chemistry").prepend("<option value=0>" +"未选择"+ "</option>");
                    $("#geography").prepend("<option value=0>" +"未选择"+ "</option>");
                    $("#history").prepend("<option value=0>" +"未选择"+ "</option>");
                    $("#polotics").prepend("<option value=0>" +"未选择"+ "</option>");
                    $("#biology").prepend("<option value=0>" +"未选择"+ "</option>");
                    $.each(res, function (index, item) {   //循环后台返回的json数据

                            switch (item.subject) {
                                case "语文":
                                    //如果是当前老师给选中
                                    if (data.chineseTeacherInfo!=null&&item.tcId == data.chineseTeacherInfo.tcId) {
                                        $("#chinese").append("<option value=" + res[index].tcId + " selected>" + res[index].name + "</option>");
                                    } else {
                                        $("#chinese").append("<option value=" + res[index].tcId + ">" + res[index].name + "</option>");
                                    }
                                    break;
                                case "数学":
                                    //如果是当前老师给选中
                                    if (data.mathTeacherInfo!=null&&item.tcId == data.mathTeacherInfo.tcId) {
                                        $("#math").append("<option value=" + res[index].tcId + " selected>" + res[index].name + "</option>");
                                    } else {
                                        $("#math").append("<option value=" + res[index].tcId + ">" + res[index].name + "</option>");
                                    }
                                    break;
                                case "英语":
                                    //如果是当前老师给选中
                                    if (data.englishTeacherInfo!=null&&item.tcId == data.englishTeacherInfo.tcId) {
                                        $("#english").append("<option value=" + res[index].tcId + " selected>" + res[index].name + "</option>");
                                    } else {
                                        $("#english").append("<option value=" + res[index].tcId + ">" + res[index].name + "</option>");
                                    }
                                    break;
                                case "物理":
                                    //如果是当前老师给选中
                                    if (data.physicsTeacherInfo!=null&&item.tcId == data.physicsTeacherInfo.tcId) {
                                        $("#physics").append("<option value=" + res[index].tcId + " selected>" + res[index].name + "</option>");
                                    } else {
                                        $("#physics").append("<option value=" + res[index].tcId + ">" + res[index].name + "</option>");
                                    }
                                    break;
                                case "化学":
                                    //如果是当前老师给选中
                                    if (data.chemistryTeacherInfo!=null&&item.tcId == data.chemistryTeacherInfo.tcId) {
                                        $("#chemistry").append("<option value=" + res[index].tcId + " selected>" + res[index].name + "</option>");
                                    } else {
                                        $("#chemistry").append("<option value=" + res[index].tcId + ">" + res[index].name + "</option>");
                                    }
                                    break;
                                case "地理":
                                    //如果是当前老师给选中
                                    if (data.geographyTeacherInfo!=null&&item.tcId == data.geographyTeacherInfo.tcId) {
                                        $("#geography").append("<option value=" + res[index].tcId + " selected>" + res[index].name + "</option>");
                                    } else {
                                        $("#geography").append("<option value=" + res[index].tcId + ">" + res[index].name + "</option>");
                                    }
                                    break;
                                case "历史":
                                    //如果是当前老师给选中
                                    if (data.historyTeacherInfo!=null&&item.tcId == data.historyTeacherInfo.tcId) {
                                        $("#history").append("<option value=" + res[index].tcId + " selected>" + res[index].name + "</option>");
                                    } else {
                                        $("#history").append("<option value=" + res[index].tcId + ">" + res[index].name + "</option>");
                                    }
                                    break;
                                case "政治":
                                    //如果是当前老师给选中
                                    if (data.poloticsTeacherInfo!=null&&item.tcId == data.poloticsTeacherInfo.tcId) {
                                        $("#polotics").append("<option value=" + res[index].tcId + " selected>" + res[index].name + "</option>");
                                    } else {
                                        $("#polotics").append("<option value=" + res[index].tcId + ">" + res[index].name + "</option>");
                                    }
                                    break;
                                case "生物":
                                    //如果是当前老师给选中
                                    if (data.biologyTeacherInfo!=null&&item.tcId == data.biologyTeacherInfo.tcId) {
                                        $("#biology").append("<option value=" + res[index].tcId + " selected>" + res[index].name + "</option>");
                                    } else {
                                        $("#biology").append("<option value=" + res[index].tcId + ">" + res[index].name + "</option>");
                                    }
                                    break;

                            }



                        //new Option方法是新建一个option，第一个参数是需要显示的值，第二个参数是option的value值,然后append到下拉框中。
                        // $('#teachers').append(new Option(item.name, item.tcId));
                    })
                    layui.form.render("select"); //更新所有select标签的状态
                }
            })

            //obj 同上
            layer.open({
                type: 1,
                title: ['修改任课老师', 'text-align:center;font-size:20px;'],
                skin: 'layui-layer-molv',
                area: ['800px', '450px'],
                content: $('#update-instructor-layer'),
                btn: ["修改", "取消"],
                btnAlign: 'c',//居中,
                yes: function (index, layero) {

                    $.post("/TeamInstructor/updateTeamInstructor",$("#update-instructor-form").serialize(),function (res) {
                        //如果修改成功
                        if(res.code==200){
                            layer.msg(res.message);
                            obj.update(res.data);//更新数据
                            layer.close(index);//关闭弹出层

                        }else{
                            layer.msg(res.message);
                        }
                    })
                }
                })

        });
        //表格的渲染
        table.render({
            elem: '#instructor',
            height: 312,
            url: '/TeamInstructor/getAllMsg' //数据接口
            ,
            page: true //开启分页
            ,
            cols: [
                [
                    {
                        field: 'ttid',
                        title: '编号',
                        type: 'numbers',
                        width: 70,
                    },
                    {
                        field: 'teamInfo',
                        title: '班级名',
                        width: 110,
                        templet: function (d) {
                            return d.teamInfo.gradeInfo.gradeType + "(" + d.teamInfo.tname+")";
                        }
                    },
                    {
                        field: 'teamType',
                        title: '班级类型',
                        width: 90,
                        templet: function (d) {
                            if(d.teamInfo!=null){
                                return d.teamInfo.teamType;}
                            else {
                                return "-------";}

                        }
                    },
                    {
                        field: 'chineseTeacherInfo',
                        title: '语文',
                        width: 75,
                        templet: function (d) {
                            if(d.chineseTeacherInfo!=null){
                                return d.chineseTeacherInfo.name;}
                            else {
                                return "-------";}

                        }
                    },
                    {
                        field: 'mathTeacherInfo',
                        title: '数学',
                        width: 75,
                        templet: function (d) {
                            if(d.mathTeacherInfo!=null){
                                return d.mathTeacherInfo.name;}
                            else {
                                return "-------";}

                        }
                    },
                    {
                        field: 'englishTeacherInfo',
                        title: '英语',
                        width: 75,
                        templet: function (d) {
                            if(d.englishTeacherInfo!=null){
                                return d.englishTeacherInfo.name;}
                            else {
                                return "-------";}

                        }
                    },
                    {
                        field: 'physicsTeacherInfo',
                        title: '物理',
                        width: 75,
                        templet: function (d) {
                            if(d.physicsTeacherInfo!=null){
                                return d.physicsTeacherInfo.name;}
                            else {
                                return "-------";}

                        }
                    },
                    {
                        field: 'chemistryTeacherInfo',
                        title: '化学',
                        width: 75,
                        templet: function (d) {
                            if(d.chemistryTeacherInfo!=null){
                                return d.chemistryTeacherInfo.name;}
                            else {
                                return "-------";}

                        }
                    },
                    {
                        field: 'geographyTeacherInfo',
                        title: '地理',
                        width: 75,
                        templet: function (d) {
                            if(d.geographyTeacherInfo!=null){
                                return d.geographyTeacherInfo.name;}
                            else {
                                return "-------";}
                        }
                    },
                    {
                        field: 'historyTeacherInfo',
                        title: '历史',
                        width: 75,
                        templet: function (d) {
                            if(d.historyTeacherInfo!=null){
                                return d.historyTeacherInfo.name;}
                            else {
                                return "-------";}

                        }
                    },
                    {
                        field: 'poloticsTeacherInfo',
                        title: '政治',
                        width: 75,
                        templet: function (d) {
                            if(d.poloticsTeacherInfo!=null){
                                return d.poloticsTeacherInfo.name;}
                            else {
                                return "-------";}
                        }
                    },
                    {
                        field: 'biologyTeacherInfo',
                        title: '生物',
                        width: 75,
                        templet: function (d) {
                            if(d.biologyTeacherInfo!=null){
                                return d.biologyTeacherInfo.name;}
                            else {
                                return "-------";}
                        }
                    },
                ]]
        })

    })
</script>
</body>
</html>